﻿;;; -*-Emacs-Lisp-*-
;;;  .emacs
;;;
;;;  $Id: .emacs,v 1.3 2011/11/30 10:35:59 okita Exp $

;; comment out for using Commanda.
;; prequire 'un-define)

;;; 行末の空白を表示
(setq-default show-trailing-whitespace t)

;; other setting
(setq max-specpdl-size 6000)
(setq max-lisp-eval-depth 1000)

;; Jump Frame
(defun my-other-window-r1 ()
  (interactive)
  (other-window -1))
(global-set-key "\M-o" 'my-other-window-r1)

;; Word Search
(add-hook 'isearch-mode-hook
          (function (lambda ()
                      (define-key isearch-mode-map "\M-w" 'isearch-toggle-word-search))))

(defun isearch-toggle-word-search ()
  (interactive)
  (setq isearch-word (not isearch-word))
  (if isearch-word (setq isearch-regexp nil))
  (setq isearch-success t isearch-adjusted t)
  (isearch-update))

;; Auto Save Mode
(auto-save-mode nil)

;; indent by tab-width 8
(setq-default indent-tabs-mode nil)
(setq-default tab-width 4)

;; By an unknown contributor
(global-set-key "\M-p" 'match-paren)

(defun match-paren (arg)
  "Go to the matching paren if on a paren; otherwise insert %."
  (interactive "p")
  (cond ((looking-at "\\s\(") (forward-list 1) (backward-char 1))
        ((looking-at "\\s\)") (forward-char 1) (backward-list 1))
        (t (self-insert-command (or arg 1)))))

;; for display time
(setq display-time-24hr-format t)
(setq display-time-day-and-date t)
(display-time)

;; for display column no
(column-number-mode t)
;; for hilight bracket
(show-paren-mode t)

(defun line-to-top-of-window ()
  "Move the line point is on to top of window."
  (interactive)
  (recenter 0))

;; for define key bind
(global-set-key "\C-t" 'line-to-top-of-window)
(global-set-key "\C-h" 'delete-backward-char)

;; added underline
(global-set-key [f9] 'global-hl-line-mode)
(setq hl-line-face 'underline)

;; for cursor speed-up
(defvar scroll-speedup-count 5)
(defvar scroll-speedup-rate 2)
(defvar scroll-speedup-time 200)

(defvar scroll-step-default 1)
(defvar scroll-step-count 1)
(defvar scroll-speedup-zero (current-time))

(defun scroll-speedup-setspeed ()
  (let* ((now (current-time))
         (min (- (car now) (car scroll-speedup-zero)))
         (sec (- (car (cdr now)) (car (cdr scroll-speedup-zero))))
         (msec (/ (- (car (cdr (cdr now)))
                     (car (cdr (cdr scroll-speedup-zero))))
                  1000))
         (lag (+ (* 60000 min) (* 1000 sec) msec)))
    (if (> lag scroll-speedup-time)
        (progn
          (setq scroll-step-default 1)
          (setq scroll-step-count 1))
      (setq scroll-step-count (+ 1 scroll-step-count)))
    (setq scroll-speedup-zero (current-time))))

(defun scroll-speedup-next-line (arg)
  (if (= (% scroll-step-count scroll-speedup-count) 0)
      (setq scroll-step-default
            (+ scroll-speedup-rate scroll-step-default)))
  (if (string= arg 'next)
      (forward-line scroll-step-default)
    (forward-line (* -1 scroll-step-default))))

(defadvice next-line
  (around next-line-speedup activate)
  (if (and (string= last-command 'next-line)
           (interactive-p))
      (progn
        (scroll-speedup-setspeed)
        (scroll-speedup-next-line 'next))
    (setq scroll-step-default 1)
    (setq scroll-step-count 1)
    ad-do-it))

(defadvice previous-line
  (around previous-line-speedup activate)
  (if (and (string= last-command 'previous-line)
           (interactive-p))
      (progn
        (scroll-speedup-setspeed)
        (scroll-speedup-next-line 'previous))
    (setq scroll-step-default 1)
    (setq scroll-step-count 1)
    ad-do-it))
;; ---End cursor speed up---

;; set load-path
(setq load-path (cons (expand-file-name "~/elisp") load-path))

;; set additional Info directory
(setq Info-default-directory-list
      (cons (expand-file-name "~/info") Info-default-directory-list))

;; for global replace feature (in grep-edit.el)
(require 'grep)
(require 'grep-edit)

(defadvice grep-edit-change-file (around inhibit-read-only activate)
  ""
  (let ((inhibit-read-only t))
    ad-do-it))
;; (progn (ad-disable-advice 'grep-edit-change-file 'around 'inhibit-read-only) (ad-update 'grep-edit-change-file))
(defun my-grep-edit-setup ()
  (define-key grep-mode-map '[up] nil)
  (define-key grep-mode-map "\C-c\C-c" 'grep-edit-finish-edit)
  (message (substitute-command-keys "\\[grep-edit-finish-edit] to apply changes."))
  (set (make-local-variable 'inhibit-read-only) t))
(add-hook 'grep-setup-hook 'my-grep-edit-setup t)

;; langage
(set-language-environment "japanese")   ; must be comment for canna

;; encoding
(set-default-coding-systems 'shift_jis)
;;(prefer-coding-system 'utf-8-unix)
;;(setq default-buffer-file-coding-system 'utf-8)
;;(set-buffer-file-coding-system 'utf-8)
;;(set-terminal-coding-system 'utf-8)
;;(set-keyboard-coding-system 'utf-8)
;;(set-clipboard-coding-system 'utf-8)
;;(setq default-fil-name-coding-system 'utf-8)

;; 画像ファイルを表示
(auto-image-file-mode)

(custom-set-variables
  ;; custom-set-variables was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(auto-compression-mode t nil (jka-compr))
 '(blink-cursor-mode nil)
 '(column-number-mode t)
 '(diff-switches "-u")
 '(display-time-mode t)
 '(egg-conversion-auto-candidate-menu 4)
 '(js-indent-level 2)
 '(safe-local-variable-values (quote ((Syntax . Common-Lisp) (Package . CLOS))))
 '(show-paren-mode t)
 '(tool-bar-mode nil)
 '(vc-handled-backends (quote (RCS CVS))))

(custom-set-faces
  ;; custom-set-faces was added by Custom.
  ;; If you edit it by hand, you could mess it up, so be careful.
  ;; Your init file should contain only one such instance.
  ;; If there is more than one, they won't work right.
 '(default ((t (:inherit nil :stipple nil :background "SystemWindow" :foreground "SystemWindowText" :inverse-video nil :box nil :strike-through nil :overline nil :underline nil :slant normal :weight normal :height 113 :width normal :foundry "outline" :family "ＭＳ 明朝"))))
 '(compilation-info ((((class color) (min-colors 16) (background light)) (:weight bold))))
 '(diff-added ((t (:foreground "#d787ff" :weight bold))))
 '(diff-changed ((((type tty pc) (class color) (background light)) (:foreground "#d787ff" :slant italic :weight bold))))
 '(diff-indicator-removed ((t (:inherit diff-removed))))
 '(diff-removed ((t (:foreground "#8787ff" :weight bold))))
 '(ediff-current-diff-A ((((class color) (min-colors 16)) (:background "#ff8700" :foreground "black"))))
 '(ediff-current-diff-B ((((class color) (min-colors 16)) (:background "#00af00" :foreground "black"))))
 '(ediff-even-diff-Ancestor ((((class color) (min-colors 16)) (:background "Grey" :foreground "brightwhite"))))
 '(ediff-even-diff-B ((((class color) (min-colors 16)) (:background "Grey" :foreground "brightwhite"))))
 '(ediff-fine-diff-A ((((class color) (min-colors 16)) (:background "#ffaf5f" :foreground "black"))))
 '(ediff-fine-diff-B ((((class color) (min-colors 16)) (:background "#00d700" :foreground "black"))))
 '(ediff-odd-diff-A ((((class color) (min-colors 16)) (:background "Grey" :foreground "brightwhite"))))
 '(ediff-odd-diff-C ((((class color) (min-colors 16)) (:background "Grey" :foreground "brightwhite"))))
 '(font-lock-comment-face ((((class color) (min-colors 8) (background light)) (:foreground "#808080"))))
 '(font-lock-constant-face ((t nil)))
 '(font-lock-doc-face ((t (:inherit nil))))
 '(font-lock-function-name-face ((t nil)))
 '(font-lock-keyword-face ((t nil)))
 '(font-lock-string-face ((t nil)))
 '(font-lock-variable-name-face ((t nil)))
 '(font-lock-warning-face ((t (:foreground "#ff0000"))))
 '(link ((((class color) (min-colors 88) (background light)) (:underline t))))
 '(region ((((class color) (min-colors 88) (background light)) (:background "black" :foreground "white"))))
 '(trailing-whitespace ((((class color) (background light)) (:background "#eee")))))

(setq mime-setup-enable-inline-html nil)
;;(load "mime-setup")
(setq mime-edit-insert-user-agent-field nil)
(setq mime-edit-split-message nil)
(setq mime-setup-enable-inline-html nil)
;; display '"' quoted encoded words
(setq mime-header-lexical-analyzer
      '(;;eword-analyze-quoted-string
        eword-analyze-domain-literal
        eword-analyze-comment
        eword-analyze-spaces
        eword-analyze-special
        eword-analyze-encoded-word
        eword-analyze-atom))

;; WL
(autoload 'wl "wl" "Wanderlust" t)
(autoload 'wl-draft "wl-draft" "Write draft with Wanderlust." t)
(setq elmo-imap4-use-modified-utf7 t)
;; set mail-user-agent
(autoload 'wl-user-agent-compose "wl-draft" nil t)
(if (boundp 'mail-user-agent)
    (setq mail-user-agent 'wl-user-agent))
(if (fboundp 'define-mail-user-agent)
    (define-mail-user-agent
      'wl-user-agent
      'wl-user-agent-compose
      'wl-draft-send
      'wl-draft-kill
      'mail-send-hook))
(autoload 'mu-cite-original "mu-cite" nil t)
;;(add-hook 'mail-citation-hook (function mu-cite-original))
(setq mu-cite-prefix-format '(prefix-register-verbose " } "))
(setq mu-cite-top-format '(" On " date "\n        " from " wrote:\n\n"))
(setq mu-cite-cited-prefix-regexp
      "^[^<>]+>+[ \t]*")
;;(autoload 'sc-cite-original "supercite" nil t)
;;(add-hook 'mail-citation-hook 'sc-cite-original)

(add-hook 'c-mode-common-hook
          (function (lambda ()
                      (c-set-style "bsd")
                      (setq c-basic-offset 4)
                      (setq comment-column 45))))
(setq auto-mode-alist
      (cons '("\\.x\\'" . c++-mode) auto-mode-alist))
(setq auto-mode-alist
      (cons '("\\.java\\'" . c++-mode) auto-mode-alist))
;; ruby mode
(autoload 'ruby-mode "ruby-mode"
  "Mode for editing ruby source files" t)
(setq auto-mode-alist
      (append '(("\\.rb$" . ruby-mode)) auto-mode-alist))
(setq interpreter-mode-alist (append '(("ruby" . ruby-mode))
                                     interpreter-mode-alist))

;; php-mode
;;(load-library "php-mode-110")
(load-library "php-mode")
(setq auto-mode-alist
      (cons '("\\.inc\\'" . php-mode) auto-mode-alist))
(setq auto-mode-alist
      (cons '("\\.php\\'" . php-mode) auto-mode-alist))
(require 'php-mode)

;; javascript-mode
;;(setq-default c-basic-offset 4)
;;(when (load "js2" t)
;;  (setq js2-cleanup-whitespace nil
;;        js2-mirror-mode nil
;;        js2-bounce-indent-flag nil)
;;
;;  (defun indent-and-back-to-indentation ()
;;    (interactive)
;;    (indent-for-tab-command)
;;    (let ((point-of-indentation
;;           (save-excursion
;;             (back-to-indentation)
;;             (point))))
;;      (skip-chars-forward "\s " point-of-indentation)))
;;  (define-key js2-mode-map "\C-i" 'indent-and-back-to-indentation)
;;  (define-key js2-mode-map "\C-m" nil)
;;  (add-to-list 'auto-mode-alist '("\\.js$" . js2-mode)))

;; Initial major mode
;;(setq initial-major-mode 'fundamental-mode)

;; Inhibit startup message
(setq inhibit-startup-message t)

;; 70 column set
(setq-default fill-column 70)

;;(setq text-mode-hook
;;          '(lambda () (auto-fill-mode 1)
;;           (setq fill-column 70) ))
;; enable following functions
(put 'eval-expression 'disabled nil)
(put 'narrow-to-region 'disabled nil)

;; I won't need backup file.
(setq-default make-backup-files nil)

;; Don't read default.el
;;(setq inhibit-default-init t)
;; Don't add new lines
(setq next-line-add-newlines nil)

;; mouse yank commands yank at point instead of at click
(setq mouse-yank-at-point t)

;; exchange CTRL-H and DEL
(cond ((eq window-system 'x)
       (define-key function-key-map [delete] [8])
       (put 'delete 'ascii-character 8)
       (set-scroll-bar-mode 'nil)
       (blink-cursor-mode nil)        ; 'nil' cause delaying char input by xim
       (setq cursor-in-non-selected-windows nil)
       )
      ((null window-system)
       (menu-bar-mode nil)
       ))
(setq mail-self-blind t)
(setq mail-aliases t)
;;(add-hook 'mail-mode-hook
;;            '(lambda ()
;;               (auto-fill-mode nil)))

;;  change directory to HOME
(defun home ()
  "Change directory to HOME"
  (interactive)
  (cd "~"))

;; *** for gosh (Gauche) ***
(setq process-coding-system-alist
      (cons '("gosh" euc-jp . euc-jp) process-coding-system-alist))
(setq gosh-program-name "/usr/local/bin/gosh -i")

;; scheme mode
(autoload 'scheme-mode "cmuscheme" "Major mode for Scheme." t)
(autoload 'run-scheme "cmuscheme" "Run an inferior Scheme process." t)

;; run scheme
(defun scheme-other-frame ()
  "Run scheme on other frame"
  (interactive)
  (switch-to-buffer-other-frame
   (get-buffer-create "*scheme*"))
  (run-scheme scheme-program-name))
(defun scheme-other-window ()
  "Run scheme on other window"
  (interactive)
  (switch-to-buffer-other-window
   (get-buffer-create "*scheme*"))
  (run-scheme gosh-program-name))
(defun gauche-info ()
  (interactive)
  (switch-to-buffer-other-frame
   (get-buffer-create "*info*"))
  (info "/usr/local/info/gauche-refj.info.gz"))
(define-key global-map
  "\C-xS" 'scheme-other-frame)
(define-key global-map
  "\C-cS" 'scheme-other-window)
(define-key global-map
  "\C-cI" 'gauche-info)

;; define indent
(put 'and-let* 'scheme-indent-function 1)
(put 'begin0 'scheme-indent-function 0)
(put 'call-with-client-socket 'scheme-indent-function 1)
(put 'call-with-input-conversion 'scheme-indent-function 1)
(put 'call-with-input-file 'scheme-indent-function 1)
(put 'call-with-input-process 'scheme-indent-function 1)
(put 'call-with-input-string 'scheme-indent-function 1)
(put 'call-with-iterator 'scheme-indent-function 1)
(put 'call-with-output-conversion 'scheme-indent-function 1)
(put 'call-with-output-file 'scheme-indent-function 1)
(put 'call-with-output-string 'scheme-indent-function 0)
(put 'call-with-temporary-file 'scheme-indent-function 1)
(put 'call-with-values 'scheme-indent-function 1)
(put 'dolist 'scheme-indent-function 1)
(put 'dotimes 'scheme-indent-function 1)
(put 'if-match 'scheme-indent-function 2)
(put 'let*-values 'scheme-indent-function 1)
(put 'let-args 'scheme-indent-function 2)
(put 'let-keywords* 'scheme-indent-function 2)
(put 'let-match 'scheme-indent-function 2)
(put 'let-optionals* 'scheme-indent-function 2)
(put 'let-syntax 'scheme-indent-function 1)
(put 'let-values 'scheme-indent-function 1)
(put 'let/cc 'scheme-indent-function 1)
(put 'let1 'scheme-indent-function 2)
(put 'letrec-syntax 'scheme-indent-function 1)
(put 'make 'scheme-indent-function 1)
(put 'multiple-value-bind 'scheme-indent-function 2)
(put 'match 'scheme-indent-function 1)
(put 'parameterize 'scheme-indent-function 1)
(put 'parse-options 'scheme-indent-function 1)
(put 'receive 'scheme-indent-function 2)
(put 'rxmatch-case 'scheme-indent-function 1)
(put 'rxmatch-cond 'scheme-indent-function 0)
(put 'rxmatch-if  'scheme-indent-function 2)
(put 'rxmatch-let 'scheme-indent-function 2)
(put 'syntax-rules 'scheme-indent-function 1)
(put 'unless 'scheme-indent-function 1)
(put 'until 'scheme-indent-function 1)
(put 'when 'scheme-indent-function 1)
(put 'while 'scheme-indent-function 1)
(put 'with-builder 'scheme-indent-function 1)
(put 'with-error-handler 'scheme-indent-function 0)
(put 'with-error-to-port 'scheme-indent-function 1)
(put 'with-input-conversion 'scheme-indent-function 1)
(put 'with-input-from-port 'scheme-indent-function 1)
(put 'with-input-from-process 'scheme-indent-function 1)
(put 'with-input-from-string 'scheme-indent-function 1)
(put 'with-iterator 'scheme-indent-function 1)
(put 'with-module 'scheme-indent-function 1)
(put 'with-output-conversion 'scheme-indent-function 1)
(put 'with-output-to-port 'scheme-indent-function 1)
(put 'with-output-to-process 'scheme-indent-function 1)
(put 'with-output-to-string 'scheme-indent-function 1)
(put 'with-port-locking 'scheme-indent-function 1)
(put 'with-string-io 'scheme-indent-function 1)
(put 'with-time-counter 'scheme-indent-function 1)
(put 'with-signal-handlers 'scheme-indent-function 1)
(put 'with-locking-mutex 'scheme-indent-function 1)
(put 'guard 'scheme-indent-function 1)

(put 'dired-find-alternate-file 'disabled nil)

;; original setting by Okita
(put 'set-goal-column 'disabled nil)

;; Show line number
(require 'wb-line-number)
(setq truncate-partial-width-windows nil)
(set-scroll-bar-mode nil)
(setq wb-line-number-scroll-bar t)
(global-set-key [f8] 'wb-line-number-toggle)

;; subversion
(autoload 'svn-status "dsvn" "Run `svn status'." t)
(autoload 'svn-update "dsvn" "Run `svn update'." t)
(define-key global-map
  "\C-xvn" 'svn-status)
(define-key global-map
  "\C-xvk" 'svn-update)
(define-key global-map
  "\C-xvh" 'svn-update-help)

;; color customize
(defface test-face-1
  '((((class color)
      (background dark))
     (:foreground "light blue"))
    (((class color)
      (background light))
     (:foreground "MidnightBlue"))
    (t
     (:italic t)))
  "Citation face.")

;; for edict
(autoload 'edict-search-english "edict"
  "Search for a translation of an English word" t)
(autoload 'edict-search-kanji "edict"
  "Search for a translation of a Kanji sequence" t)
(setq *edict-files* '("c:/Users/okita/Documents/elisp/etc/edict/edict"))

;; for google search
(load "google")

;; okita original elisp
(load "okita-org")
(load "rand-string")					;ランダム文字列生成

;; デフォルトの透明度を設定する (85%)
;(add-to-list 'default-frame-alist '(alpha . 85))

;; set short cut key
(define-key global-map
  "\C-x\M-r" 'revert-buffer)

;; util.el
(load "util")

;; html5
(add-to-list 'load-path "~/elisp/html5-el/")
(eval-after-load "rng-loc"
  '(add-to-list 'rng-schema-locating-files "~/elisp/html5-el/schemas.xml"))
(require 'whattf-dt)

;; autoload visual-basic-mode
(autoload 'visual-basic-mode "visual-basic-mode" "Visual Basic mode." t)
(add-to-list 'auto-mode-alist '("\\.vbs\\'" . visual-basic-mode)) ; VBscript
(add-to-list 'auto-mode-alist '("\\.vb\\'" . visual-basic-mode))  ; visual basic .NET file
(add-to-list 'auto-mode-alist '("\\.bas\\'" . visual-basic-mode)) ; visual basic form
(add-to-list 'auto-mode-alist '("\\.frm\\'" . visual-basic-mode)) ; basic language source
(add-to-list 'auto-mode-alist '("\\.cls\\'" . visual-basic-mode)) ; C++ class definition file

;; mcomplete
(require 'mcomplete)
(turn-on-mcomplete-mode)
(defcustom mcomplete-default-method-set
  '(mcomplete-prefix-method mcomplete-substr-method)
  "List of completion methods.  The first method is applied first."
  :type  '(repeat function)
  :group 'mcomplete)
